<template>
  <div class="Dialog">
    <el-dialog :visible.sync="visible" :title="dialog_params.title" :width="dialog_params.width"
      :modal="dialog_params.modal" center :close-on-click-modal="false" :close-on-press-escape="false"
      :show-close="false">
      <el-row>
        <el-col :span="14">
          <el-row>
            <el-col :span="8" style="font-size: 15px">总转化金额：{{detail.dealNum}}</el-col>
            <el-col :span="11" :offset="2">
              <span style="font-size: 15px">{{detail.startDate}} 至 {{detail.endDate}}</span>
            </el-col>
          </el-row>
          <el-row>
            <div id="bar"></div>
          </el-row>
        </el-col>
        <el-col :span="9">
          <el-row>
            <h1>{{detail.missionName}}</h1>
          </el-row>
          <el-row class="detail-row">
            <span class="detail-title">目标人群：<span>{{detail.groupName}}</span></span>
          </el-row>
          <el-row class="detail-row">
            <span class="detail-title">创建人：<span>{{detail.creater}}</span></span>
          </el-row>
          <el-row class="detail-row">
            <span class="detail-title">推送内容：<span>{{detail.messageInfo}}</span></span>
          </el-row>
          <el-row class="detail-row">
            <span class="detail-title">推送时间：<span>{{detail.sendTime}}</span></span>
          </el-row>
        </el-col>
      </el-row>
      <!--弹出层按钮居中-->
      <div style="text-align: center">
        <el-button @click="modal_close" size="small">关闭</el-button>
      </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import echarts from 'echarts'
  export default {
    name: 'brandDialog',
    props: {
      visible: {
        type: Boolean,
        default: false
      },
      dialog_params: {
        missionType: String,
        groupId: String,
        addTime: String,
        width: String,
      }
    },
    data() {
      return {
        detail: {
          groupName: '',
          missionName: '',
          messageInfo: '',
          creater: '',
          addTime: '',
          startDate: '',
          endDate: '',
          targetNum: '',
          sendNum: '',
          clickNum: '',
          dealNum: '',
        },
        myChart: {},
        barData: [],
        xData: ['目标人数', '推送人数', '点击人数'], //x轴显示数据
        yData: [], //y轴数据
        color: ['#325B69', '#698570', '#AE5548']
      };
    },
    created() {
      this.$nextTick(() => {
        this.$http.post('api/userprofile-platform/v1/Market/marketDetail', {
          missionType: this.dialog_params.missionType,
          groupId: this.dialog_params.groupId,
          addTime: this.dialog_params.addTime
        }).then(res => {
          if (res.data.code == 1) {
            this.$message.success(res.data.message)
            this.detail = res.data.data
            this.yData.push(this.detail.targetNum)
            this.yData.push(this.detail.sendNum)
            this.yData.push(this.detail.clickNum)
            this.getMyCharts()
          } else {
            this.$message.error(res.data.msg)
            this.modal_close()
          }
        })
      })
    },
    methods: {
      getMyCharts() {
        this.myChart = echarts.init(document.getElementById('bar'));
        let option = {
          tooltip: {
            trigger: 'item',
          },
          legend: {
            show: false
          },
          toolbox: {
            show: false
          },
          color: this.color,
          calculable: true,
          grid: {
            width: '75%',
            top: '18%',
            height: '65%',
            left: '15%',
            containLabel: false
          },
          xAxis: [{
            name: '',
            type: 'category',
            axisLine: {
              show: true,
              lineStyle: {
                color: "rgba(255,225,255,1)",
                width: 2,
                type: "solid"
              }
            },
            axisTick: {
              show: false
            },

            nameTextStyle: {
              color: 'rgba(255, 255, 255, 0.69)'
            },
            axisLabel: {
              textStyle: {
                color: 'black'
              },
              interval: 0,
              rotate: 0,
              fontSize: '3vmax'
            },
            data: this.xData
          }],
          yAxis: [{
            axisLine: {
              show: false
            },
            nameLocation: 'end',
            nameGap: 20,
            nameRotate: 0,
            axisTick: {
              show: false
            },
            splitLine: {
              lineStyle: {
                width: 2,
                color: ['rgba(255, 230, 230, 1)']
              }
            },
            axisLabel: {
              textStyle: {
                color: 'black',
              },
            },
            name: '销量(单位:万辆)',
            type: 'value',
            nameTextStyle: {
              color: 'rgba(255, 255, 255, 0.69)'
            }
          }],
          series: [{
            type: 'bar',
            data: this.yData,
            barWidth: 30,
            itemStyle: {
              color: new echarts.graphic.LinearGradient(
                0, 0, 0, 1,
                [{
                    offset: 0,
                    color: '#83bff6'
                  },
                  {
                    offset: 0.6,
                    color: '#1686e1'
                  },
                  {
                    offset: 1,
                    color: '#1374c3'
                  }
                ]
              )
            },
          }]
        }
        this.myChart.setOption(option);
        window.addEventListener("resize", () => {
          this.myChart.resize();
        });
      },

      /**
       * 关闭模态框
       */
      modal_close() {
        this.$emit('update:visible', false)
      }
    }
  };

</script>

<style scoped>
  #bar {
    width: 100%;
    height: 300px;
  }

  .detail-row {
    margin-bottom: 15px;
  }

  .detail-title {
    font-size: 15px;
    color: #999;
  }

</style>
